package com.weixing.mall.provider.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weixing.mall.provider.mapper.GoodsTransBillOperationMapper;
import com.weixing.mall.provider.model.domain.GoodsTransBillOperation;
import com.weixing.mall.provider.model.dto.GoodsTransBillOperationDto;
import com.weixing.mall.provider.model.vo.GoodsTransBillOperationVo;
import com.weixing.mall.provider.service.IGoodsTransBillOperationService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @ClassName GoodsTransBillOperationServiceImpl
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/10/28
 * @Version 1.0
 **/
/**
 * <p>
 * 仓库模块-调拨单操作记录表 服务实现类
 * </p>
 *
 * @author Small
 * @since 2019-11-15
 */
@Service
public class GoodsTransBillOperationServiceImpl extends ServiceImpl<GoodsTransBillOperationMapper, GoodsTransBillOperation> implements IGoodsTransBillOperationService {

    @Override
    public List<GoodsTransBillOperationVo> getOperationByTransBillId(Long transBillId) {
        return baseMapper.getOperationByTransBillId(transBillId);
    }

    @Override
    public void create(GoodsTransBillOperationDto goodsTransBillOperationDto, Long uid) {
        GoodsTransBillOperation goodsTransBillOperation = new GoodsTransBillOperation();
        //操作人默认当前登录人
        goodsTransBillOperationDto.setOperator(uid);
        BeanUtils.copyProperties(goodsTransBillOperationDto,goodsTransBillOperation);
        if(null != goodsTransBillOperationDto.getStatus()){
            goodsTransBillOperation.setStatus(goodsTransBillOperationDto.getStatus().getValue());
        }
        if (null == goodsTransBillOperationDto.getId()){
            goodsTransBillOperation.setCreatedBy(uid);
            save(goodsTransBillOperation);
        }else{
            goodsTransBillOperation.setUpdatedBy(uid);
            goodsTransBillOperation.setUpdatedTime(new Date());
            updateById(goodsTransBillOperation);
        }
    }
}
